<html>
<head><meta charset="utf-8"><title>Type restrictions · project-inline-asm · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/index.html">project-inline-asm</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Type.20restrictions.html">Type restrictions</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="186458133"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Type%20restrictions/near/186458133" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Type.20restrictions.html#186458133">(Jan 24 2020 at 02:41)</a>:</h4>
<p>It just occurred to me that we don't really need to care about what types a particular register class accepts, e.g. the SSE register class accepts 128-bit vectors but not i128.</p>



<a name="186458189"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Type%20restrictions/near/186458189" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Type.20restrictions.html#186458189">(Jan 24 2020 at 02:42)</a>:</h4>
<p>We can just <code>transmute</code> any operand to a type suitable for the backend, in which case we only need to care about the register size, not the actual types.</p>



<a name="186458503"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Type%20restrictions/near/186458503" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Type.20restrictions.html#186458503">(Jan 24 2020 at 02:50)</a>:</h4>
<p>With that in mind, should we revisit the rules for what types a register class can accept? Currently only integer/float/pointer primitive types are allowed. We could extend that to any type as long as it can fit in the register.</p>



<a name="186458525"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Type%20restrictions/near/186458525" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Type.20restrictions.html#186458525">(Jan 24 2020 at 02:51)</a>:</h4>
<p>Let's take RISC-V's <code>f</code> register class which only accepts <code>f32</code> and <code>f64</code> as an example: should we allow an <code>i64</code> operand? An <code>i8</code> operand? A <code>(u8, u8, u8)</code> operand?</p>



<a name="186463710"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Type%20restrictions/near/186463710" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Type.20restrictions.html#186463710">(Jan 24 2020 at 05:05)</a>:</h4>
<p>not a tuple</p>



<a name="186463760"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Type%20restrictions/near/186463760" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Type.20restrictions.html#186463760">(Jan 24 2020 at 05:06)</a>:</h4>
<p>more generally, anything that you should not <em>actually</em> transmute to the register's real type should not work here.</p>



<a name="186498815"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Type%20restrictions/near/186498815" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Type.20restrictions.html#186498815">(Jan 24 2020 at 14:58)</a>:</h4>
<p>What about <code>struct S(u16, u16)</code>? Should we allow this to fit in a 32-bit register?</p>



<a name="186498865"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Type%20restrictions/near/186498865" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Type.20restrictions.html#186498865">(Jan 24 2020 at 14:59)</a>:</h4>
<p>The current RFC does allow smaller values to go into a larger register. The most common case is putting a f32 value into a 64-bit float register which supports both f32 and f64.</p>



<a name="186502048"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Type%20restrictions/near/186502048" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Type.20restrictions.html#186502048">(Jan 24 2020 at 15:31)</a>:</h4>
<p>Hmm, I'm suddenly having an urge to redesign the register classes...</p>



<a name="186502074"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Type%20restrictions/near/186502074" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Type.20restrictions.html#186502074">(Jan 24 2020 at 15:31)</a>:</h4>
<p>transmuting an S value to u32 would be UB in normal Rust. I can't see any possible path for allowing it into inline asm without also effectively stabilizing what the transmute would be in other contexts (since those other contexts could just use an inline asm move to do the conversion).</p>
<p>Any automatic same-size conversion will have to approximately follow the safe-transmute rules. ideally we could start with a few <em>specific</em> auto-conversions (such as f32/u32/i32) and then leave a "future extension" note for general "whatever safe transmute would let you do can now automatically be done here".</p>
<p>for different size conversions, having automatic sign extension or f32-&gt;f64 or whatever seems a lot easier to grasp without accidentally affecting other parts of the language. we would still need some restrictions.</p>



<a name="186502212"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Type%20restrictions/near/186502212" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Type.20restrictions.html#186502212">(Jan 24 2020 at 15:33)</a>:</h4>
<p>The current rule is that if you pass in a smaller type, the upper bits contain an undefined value.</p>



<a name="186502250"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Type%20restrictions/near/186502250" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Type.20restrictions.html#186502250">(Jan 24 2020 at 15:34)</a>:</h4>
<p>This works well for x86, where instructions that write to <code>al</code> leave the other bits unchanged, while on other architectures it clears the upper bits.</p>



<a name="186502331"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Type%20restrictions/near/186502331" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Type.20restrictions.html#186502331">(Jan 24 2020 at 15:34)</a>:</h4>
<p>Also we want to be able to pass SIMD vectors into inline asm, for example for SSE registers.</p>



<a name="186502382"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Type%20restrictions/near/186502382" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Type.20restrictions.html#186502382">(Jan 24 2020 at 15:35)</a>:</h4>
<p>sounds initially fine, and maybe fixable down the line too</p>



<a name="186502917"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Type%20restrictions/near/186502917" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Type.20restrictions.html#186502917">(Jan 24 2020 at 15:40)</a>:</h4>
<p>Why is transmuting (u16, u16) to u32 UB? Is it just because of the undefined field order? (i.e. it would be fine if it was repr(C))</p>



<a name="186503331"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Type%20restrictions/near/186503331" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Type.20restrictions.html#186503331">(Jan 24 2020 at 15:45)</a>:</h4>
<p>correct</p>



<a name="186503342"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Type%20restrictions/near/186503342" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Type.20restrictions.html#186503342">(Jan 24 2020 at 15:45)</a>:</h4>
<p>From an implementation point of view, it feel simpler to just allow arbitrary transmutes and only checking the size of the type during type checking.</p>



<a name="186503583"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Type%20restrictions/near/186503583" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Type.20restrictions.html#186503583">(Jan 24 2020 at 15:48)</a>:</h4>
<p>yes it would be simpler to implement, but you'd effectively be enabling a lot of accidental UB, so probably that is a poor plan.</p>
<p>if anything, stick to a restricted list of primitives and relax the restrictions later.</p>



<a name="186506349"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Type%20restrictions/near/186506349" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Type.20restrictions.html#186506349">(Jan 24 2020 at 16:17)</a>:</h4>
<p>I would go even further and question the wisdom of allowing smaller types and making the highest bits undefined. Experience from C shows that people keep getting it wrong (assuming it's guaranteed to either sign- or zero-extended although neither GCC nor Clang make any guarantees about it) and it appears to work for a long time until the compiler changes and something breaks, forcing people to write patches that explicitly do the intended extension. Just this week I saw another example of this with <a href="https://www.openwall.com/lists/musl/2020/01/15/2" target="_blank" title="https://www.openwall.com/lists/musl/2020/01/15/2">https://www.openwall.com/lists/musl/2020/01/15/2</a></p>



<a name="186521207"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Type%20restrictions/near/186521207" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Type.20restrictions.html#186521207">(Jan 24 2020 at 18:44)</a>:</h4>
<p><span class="user-mention" data-user-id="143274">@Amanieu</span> Just to confirm, you're suggesting manual transmutes, not automatic conversions, right?</p>



<a name="186521267"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Type%20restrictions/near/186521267" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Type.20restrictions.html#186521267">(Jan 24 2020 at 18:45)</a>:</h4>
<p>I think people should be able to transmute u64 to f64, for instance, and feed that in to a floating point register. But by default feeding in a u64 should give a type error, to help reduce common errors.</p>



<a name="186521375"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Type%20restrictions/near/186521375" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Type.20restrictions.html#186521375">(Jan 24 2020 at 18:46)</a>:</h4>
<p>This certainly addresses my concern about vector types vs u128 though; I don't mind having to transmute there.</p>



<a name="186524984"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Type%20restrictions/near/186524984" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Type.20restrictions.html#186524984">(Jan 24 2020 at 19:26)</a>:</h4>
<p><span class="user-mention" data-user-id="239881">@Josh Triplett</span> Actually I was thinking of allowing any type, as long as it has the same size as the target register.</p>



<a name="186525151"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Type%20restrictions/near/186525151" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Type.20restrictions.html#186525151">(Jan 24 2020 at 19:28)</a>:</h4>
<p><span class="user-mention" data-user-id="124289">@rkruppe</span> That's a very good point, but at the same time it can make asm! very unergonomic to use. For example you would have to explicitly cast any integer constants to u64 before passing them into a register (since integer default to i32).</p>



<a name="186525198"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Type%20restrictions/near/186525198" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Type.20restrictions.html#186525198">(Jan 24 2020 at 19:29)</a>:</h4>
<p>Same with floats: it would suck to have to zero-extend float types to 128 bits to put them in a SSE register</p>



<a name="186526083"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Type%20restrictions/near/186526083" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Type.20restrictions.html#186526083">(Jan 24 2020 at 19:36)</a>:</h4>
<p>if a register only accepts u64 then the literal in that place should be forced to u64.</p>
<p>same as</p>
<div class="codehilite"><pre><span></span><span class="kd">let</span><span class="w"> </span><span class="n">a</span>: <span class="kt">u64</span> <span class="o">=</span><span class="w"> </span><span class="mi">5</span><span class="p">;</span><span class="w"></span>
</pre></div>


<p>makes 5 be a u64 literal</p>



<a name="186527311"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Type%20restrictions/near/186527311" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Type.20restrictions.html#186527311">(Jan 24 2020 at 19:48)</a>:</h4>
<p>"Sizes must match exactly or it's an error" isn't the only way to resolve this. There could be rules for (register class, type) combinations where it's obvious which extensions is the right one, so that only obscure things like <code>u64</code> in an XMM register need manual extension. There could also be an explicit flag on the operand for opting into the "upper bits can be anything" behavior (LLVM calls this <code>anyext</code> which is a good enough name IMO).</p>



<a name="186527577"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Type%20restrictions/near/186527577" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Type.20restrictions.html#186527577">(Jan 24 2020 at 19:51)</a>:</h4>
<p>Your point about integer literals defaulting to i32 is even more reason to move away from "upper bits unspecified", because those two things together form a huge footgun.</p>



<a name="186528982"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Type%20restrictions/near/186528982" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Type.20restrictions.html#186528982">(Jan 24 2020 at 20:05)</a>:</h4>
<p><span class="user-mention" data-user-id="143274">@Amanieu</span> I feel like "size matches" alone would be too error-prone, and not so common that a transmute is too much to ask.</p>



<a name="186529225"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Type%20restrictions/near/186529225" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Type.20restrictions.html#186529225">(Jan 24 2020 at 20:07)</a>:</h4>
<p>If we can offer a bit of type checking, like making sure a value for rax is a u64 or i64 rather than an f64, that seems more likely to catch an error than to flag code that really did want to do that. And one transmute handles the latter case.</p>



<a name="186529297"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Type%20restrictions/near/186529297" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Type.20restrictions.html#186529297">(Jan 24 2020 at 20:08)</a>:</h4>
<p>If someone has code that repeatedly has that pattern, they could always make a wrapper macro or a wrapper function.</p>



<a name="186530264"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Type%20restrictions/near/186530264" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Type.20restrictions.html#186530264">(Jan 24 2020 at 20:21)</a>:</h4>
<p>in fact f64 and f32 already have such a method <a href="https://doc.rust-lang.org/std/primitive.f64.html#method.to_bits" target="_blank" title="https://doc.rust-lang.org/std/primitive.f64.html#method.to_bits">https://doc.rust-lang.org/std/primitive.f64.html#method.to_bits</a></p>



<a name="186540478"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Type%20restrictions/near/186540478" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Type.20restrictions.html#186540478">(Jan 24 2020 at 22:26)</a>:</h4>
<p>So how about this then:<br>
(x86_64)</p>
<ul>
<li>For <code>reg</code> we only accept <code>i64</code> (and <code>usize</code> &amp; pointers). You must extend your value to <code>i64</code> if you want to use it in asm.</li>
<li>For <code>sse_reg</code> we accept <code>f32</code>, <code>f64</code> and 128-bit SIMD types.</li>
</ul>



<a name="186540646"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Type%20restrictions/near/186540646" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Type.20restrictions.html#186540646">(Jan 24 2020 at 22:28)</a>:</h4>
<p>Note that for the <code>f32</code> and <code>f64</code> case, the upper bits are undefined.</p>



<a name="186542293"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Type%20restrictions/near/186542293" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Type.20restrictions.html#186542293">(Jan 24 2020 at 22:53)</a>:</h4>
<p>i hesitate with f32/f64 into simd with unknown high bits. I feel like since the simd types are in core anyway, we should just accept those types</p>



<a name="186542311"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Type%20restrictions/near/186542311" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Type.20restrictions.html#186542311">(Jan 24 2020 at 22:53)</a>:</h4>
<p>and then people can use intrinsics to get the bits they want</p>



<a name="186550738"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Type%20restrictions/near/186550738" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Type.20restrictions.html#186550738">(Jan 25 2020 at 01:23)</a>:</h4>
<p>Here's what I think I'm going to go with:</p>
<ul>
<li>Allowed types for inline asm are integers, floats, pointers and SIMD vectors.</li>
<li>You cannot use a type larger than the register size.</li>
<li>You can use a type smaller than the register size, which will leave upper bits undefined. However the compiler will emit a warning when you do this.</li>
</ul>



<a name="186550902"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Type%20restrictions/near/186550902" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Type.20restrictions.html#186550902">(Jan 25 2020 at 01:26)</a>:</h4>
<p>we've worked pretty hard to eliminate undefined data from escaping on accident. Still seems like a potential footgun.</p>



<a name="186550950"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Type%20restrictions/near/186550950" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Type.20restrictions.html#186550950">(Jan 25 2020 at 01:27)</a>:</h4>
<p>Disallowing it completely could lead to unnecessary zero-extensions.</p>



<a name="186551739"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Type%20restrictions/near/186551739" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Type.20restrictions.html#186551739">(Jan 25 2020 at 01:47)</a>:</h4>
<p>Hmm there's also the issue of what exact is a SIMD vector. For example this is allowed:</p>
<div class="codehilite"><pre><span></span><span class="cp">#[repr(simd)]</span><span class="w"> </span><span class="k">struct</span> <span class="nc">u8x3</span><span class="p">(</span><span class="kt">u8</span><span class="p">,</span><span class="w"> </span><span class="kt">u8</span><span class="p">,</span><span class="w"> </span><span class="kt">u8</span><span class="p">);</span><span class="w"></span>
</pre></div>



<a name="186552141"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Type%20restrictions/near/186552141" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Type.20restrictions.html#186552141">(Jan 25 2020 at 01:58)</a>:</h4>
<p>use the core::arch types</p>



<a name="186552976"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Type%20restrictions/near/186552976" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Type.20restrictions.html#186552976">(Jan 25 2020 at 02:22)</a>:</h4>
<p>Except it's a bit difficult to check for those from within the compiler...</p>



<a name="186552986"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Type%20restrictions/near/186552986" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Type.20restrictions.html#186552986">(Jan 25 2020 at 02:23)</a>:</h4>
<p>Hence why I was thinking of simply allowing any type as long as it fit in the register</p>



<a name="186567126"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Type%20restrictions/near/186567126" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Type.20restrictions.html#186567126">(Jan 25 2020 at 10:14)</a>:</h4>
<p>Warnings about things that require some care but can be 100% OK and desirable are somewhat self-defeating: a project that uses the construct in question (here, relying on anyext of smaller types) more than a couple times is incentivized to disable the warning at module/crate scope, and from that point forward nobody working on the project will see the warning any more.</p>



<a name="186567205"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Type%20restrictions/near/186567205" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Type.20restrictions.html#186567205">(Jan 25 2020 at 10:17)</a>:</h4>
<p>If you argue that anyext (instead of zero/sign extension) is useful, then I think it should require an explicit opt-in on the operand in question (as I suggested before), so that you always have a reminder of the pitfall when reading, writing, and modifying code.</p>



<a name="186569639"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Type%20restrictions/near/186569639" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Type.20restrictions.html#186569639">(Jan 25 2020 at 11:29)</a>:</h4>
<p><span class="user-mention" data-user-id="124289">@rkruppe</span> You make a very good point. How about something like this:</p>
<div class="codehilite"><pre><span></span><span class="c1">// By default you must match the reg size</span>
<span class="n">asm</span><span class="o">!</span><span class="p">(</span><span class="s">&quot;&quot;</span><span class="p">,</span><span class="w"> </span><span class="k">in</span><span class="p">(</span><span class="n">reg</span><span class="p">)</span><span class="w"> </span><span class="mi">42</span><span class="k">i64</span><span class="p">);</span><span class="w"></span>
<span class="c1">// But you can opt-in to use a smaller subset of the reg</span>
<span class="n">asm</span><span class="o">!</span><span class="p">(</span><span class="s">&quot;&quot;</span><span class="p">,</span><span class="w"> </span><span class="k">in</span><span class="p">(</span><span class="n">reg</span>: <span class="mi">8</span><span class="p">)</span><span class="w"> </span><span class="mi">42</span><span class="k">i8</span><span class="p">);</span><span class="w"></span>
</pre></div>



<a name="186569882"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Type%20restrictions/near/186569882" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Type.20restrictions.html#186569882">(Jan 25 2020 at 11:36)</a>:</h4>
<p>IMO that is still too ambiguous about what happens to the upper bits. In C, I see mistaken assumptions about the kind of extension that is implied, rather than using smaller types by mere accident. How about this? (Exact keyword up for bike-shedding, as long as it makes clear it's neither zext nor sext)</p>
<div class="codehilite"><pre><span></span><span class="n">asm</span><span class="o">!</span><span class="p">(</span><span class="s">&quot;&quot;</span><span class="p">,</span><span class="w"> </span><span class="k">in</span><span class="p">(</span><span class="n">reg</span><span class="w"> </span><span class="n">anyext</span><span class="p">)</span><span class="w"> </span><span class="mi">42</span><span class="k">i8</span><span class="p">)</span><span class="w"></span>
</pre></div>



<a name="186570078"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Type%20restrictions/near/186570078" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Type.20restrictions.html#186570078">(Jan 25 2020 at 11:42)</a>:</h4>
<div class="codehilite"><pre><span></span><span class="n">asm</span><span class="o">!</span><span class="p">(</span><span class="s">&quot;&quot;</span><span class="p">,</span><span class="w"> </span><span class="k">in</span><span class="p">(</span><span class="n">reg</span><span class="w"> </span><span class="n">undefext</span><span class="p">)</span><span class="w"> </span><span class="mi">42</span><span class="k">i8</span><span class="p">)</span><span class="w"></span>
</pre></div>



<a name="186629080"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Type%20restrictions/near/186629080" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Type.20restrictions.html#186629080">(Jan 26 2020 at 17:01)</a>:</h4>
<p>This seems partly caused by our unification of register sizes in register definitions. We don't really seem to distinguish between rax, eax, ax, and al.</p>



<a name="186629133"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Type%20restrictions/near/186629133" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Type.20restrictions.html#186629133">(Jan 26 2020 at 17:02)</a>:</h4>
<p>On platforms that have a concept of different sizes for registers like that, we don't need to worry as much, I think.</p>



<a name="186629159"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Type%20restrictions/near/186629159" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Type.20restrictions.html#186629159">(Jan 26 2020 at 17:03)</a>:</h4>
<p>It's expected that if you feed a u16 into ax you should use it as ax, or take care before using it as eax/rax.</p>



<a name="186997024"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Type%20restrictions/near/186997024" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Type.20restrictions.html#186997024">(Jan 30 2020 at 15:23)</a>:</h4>
<p>I just pushed a big rework of how register classes work. It should also solve this issue.</p>



<a name="186997106"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Type%20restrictions/near/186997106" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Type.20restrictions.html#186997106">(Jan 30 2020 at 15:24)</a>:</h4>
<p>The basic idea is to allow under-sized values, but then you must use template modifiers to only access the low bits of that register.</p>



<a name="187026517"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Type%20restrictions/near/187026517" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Type.20restrictions.html#187026517">(Jan 30 2020 at 20:19)</a>:</h4>
<p>Interesting! I'll take a look. The template modifiers will make sure that you substitute in names like "ax" or "al" instead of "rax"?</p>



<a name="187026538"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Type%20restrictions/near/187026538" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Type.20restrictions.html#187026538">(Jan 30 2020 at 20:19)</a>:</h4>
<p>(And then if you want to use the whole register, you also need to declare a whole-register clobber?)</p>



<a name="187026613"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Type%20restrictions/near/187026613" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Type.20restrictions.html#187026613">(Jan 30 2020 at 20:20)</a>:</h4>
<p>Presumably you could also <code>as u64</code> if you want, and then Rust will do the movzx or movsx for you?</p>



<a name="187028024"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Type%20restrictions/near/187028024" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Type.20restrictions.html#187028024">(Jan 30 2020 at 20:37)</a>:</h4>
<p>Yes, you can sign-extend or you can use template modifiers. Either will disable the warning.</p>



<a name="187028172"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Type%20restrictions/near/187028172" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Type.20restrictions.html#187028172">(Jan 30 2020 at 20:39)</a>:</h4>
<p>*sign/zero-extend manually</p>



<a name="187029875"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Type%20restrictions/near/187029875" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Type.20restrictions.html#187029875">(Jan 30 2020 at 20:59)</a>:</h4>
<p>Hmm now that I think about it I forgot to take implicit registers into account (those not used in the template string)</p>



<a name="187031004"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Type%20restrictions/near/187031004" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Type.20restrictions.html#187031004">(Jan 30 2020 at 21:11)</a>:</h4>
<p><span class="user-mention" data-user-id="143274">@Amanieu</span> Oh, good point. An implicit <code>eax</code> or <code>al</code>, for instance, where the register isn't named so there's nowhere to apply a modifier?</p>



<a name="187031624"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Type%20restrictions/near/187031624" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Type.20restrictions.html#187031624">(Jan 30 2020 at 21:16)</a>:</h4>
<p>I am also skeptical that "apply the default modified on every single use" is a good way to opt into "upper bits undefined" behavior where it's needed (particular for things like scalars in vector registers). It doesn't makes clear what's actually happening, and it seems to make the asm way more annoying to read, write and modify than it has to be.</p>



<a name="187031966"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Type%20restrictions/near/187031966" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Type.20restrictions.html#187031966">(Jan 30 2020 at 21:19)</a>:</h4>
<p><span class="user-mention" data-user-id="124289">@rkruppe</span> It does seem preferable to be able to write the modifier once, on the <code>in</code> or <code>out</code>, rather than repeatedly as a modifier.</p>



<a name="187033568"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Type%20restrictions/near/187033568" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Type.20restrictions.html#187033568">(Jan 30 2020 at 21:34)</a>:</h4>
<p><span class="user-mention" data-user-id="124289">@rkruppe</span> What would you suggest instead?</p>



<a name="187033648"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Type%20restrictions/near/187033648" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Type.20restrictions.html#187033648">(Jan 30 2020 at 21:35)</a>:</h4>
<p>I'm a bit wary of having the syntax become too complicated, especially for these sorts of edge cases that 90% of people won't care about.</p>



<a name="187034010"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Type%20restrictions/near/187034010" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Type.20restrictions.html#187034010">(Jan 30 2020 at 21:39)</a>:</h4>
<p><span class="user-mention" data-user-id="143274">@Amanieu</span> "input this 32-bit value as a 32-bit register" doesn't seem like an edge case.</p>



<a name="187034066"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Type%20restrictions/near/187034066" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Type.20restrictions.html#187034066">(Jan 30 2020 at 21:39)</a>:</h4>
<p>And I would much rather have Rust figure out that it's a 32-bit value and use a 32-bit register automatically, rather than forcing me to specify a modifier explicitly.</p>



<a name="187034216"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Type%20restrictions/near/187034216" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Type.20restrictions.html#187034216">(Jan 30 2020 at 21:41)</a>:</h4>
<p>Also, if I'm feeding a 32-bit value into a 64-bit register, perhaps because the platform doesn't have a concept of "32-bit register", then there should be some way to avoid a gratuitous zero-extension instruction when I'm only going to use the low 32 bits.</p>



<a name="187034249"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Type%20restrictions/near/187034249" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Type.20restrictions.html#187034249">(Jan 30 2020 at 21:41)</a>:</h4>
<p>Doing so might require some kind of notation, but it shouldn't be <em>difficult</em>...</p>



<a name="187034394"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Type%20restrictions/near/187034394" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Type.20restrictions.html#187034394">(Jan 30 2020 at 21:42)</a>:</h4>
<p>I can appreciate that you don't want to add more bells and whistles but re-purposing operand modifiers has so many serious problems that it's worth adding a new piece of syntax IMO. It also won't actually affect people who don't have to care about this, unless they specifically go through the reference and try to understand the whole syntax of <code>asm!</code> and chase down what every part of the syntax means. (And those people would be reading the part about size mismatch warnings silenced by explicit modifiers too, if we went that route.)</p>



<a name="187041167"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Type%20restrictions/near/187041167" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Type.20restrictions.html#187041167">(Jan 30 2020 at 23:06)</a>:</h4>
<p>I would really prefer if the default register formatting did not depend on the type and instead defaults to the full register width (<code>rax</code> or <code>eax</code> depending on the arch). Similarly, the register formatting does not depend on what name you chose when specifying an explicit register (<code>in("rax") val</code> and <code>in("al") val</code> are treated as equivalent).</p>



<a name="187041219"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Type%20restrictions/near/187041219" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Type.20restrictions.html#187041219">(Jan 30 2020 at 23:07)</a>:</h4>
<p>In comparison, the GCC behavior when no template modifier is used is to only look at the type passed in. It also ignores the register name chosen for explicit registers.</p>



<a name="187041398"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Type%20restrictions/near/187041398" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Type.20restrictions.html#187041398">(Jan 30 2020 at 23:09)</a>:</h4>
<p>As far as I can tell nobody proposed anything like that?</p>



<a name="187041500"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Type%20restrictions/near/187041500" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Type.20restrictions.html#187041500">(Jan 30 2020 at 23:11)</a>:</h4>
<blockquote>
<p>And I would much rather have Rust figure out that it's a 32-bit value and use a 32-bit register automatically, rather than forcing me to specify a modifier explicitly.</p>
</blockquote>



<a name="187041610"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Type%20restrictions/near/187041610" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Type.20restrictions.html#187041610">(Jan 30 2020 at 23:13)</a>:</h4>
<p>Ah, I missed that part, sorry.</p>



<a name="187089367"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Type%20restrictions/near/187089367" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Type.20restrictions.html#187089367">(Jan 31 2020 at 14:43)</a>:</h4>
<p>By the way, here's what the register definitions currently look like in the code: <a href="https://github.com/Amanieu/rust/commit/0ca6992771eeb5096ed9d67d4424099067aa378c" target="_blank" title="https://github.com/Amanieu/rust/commit/0ca6992771eeb5096ed9d67d4424099067aa378c">https://github.com/Amanieu/rust/commit/0ca6992771eeb5096ed9d67d4424099067aa378c</a></p>



<a name="187101331"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Type%20restrictions/near/187101331" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Type.20restrictions.html#187101331">(Jan 31 2020 at 16:57)</a>:</h4>
<p><span class="user-mention" data-user-id="143274">@Amanieu</span> Defaulting to the full register width seems like it would make any type smaller than the register width awkward to use.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>